﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Pages_Login : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["UserName"] == null)
        {
            munviLogin.ActiveViewIndex = 0;
        }
        else
        {
            munviLogin.ActiveViewIndex = 1;
            lbStatusLogin.Text = "Welcome: " + Session["UserName"].ToString();
        }
        
    }
    protected void ASPxButton2_Click(object sender, EventArgs e)
    {
        txtUserLogin.Text = "";
        txtPassLogin.Text = "";
        txtUserLogin.Focus();
    }
    protected void btLogin_Click(object sender, EventArgs e)
    {
        if (Request.Cookies["Register"] != null)
        {
            if (Request.Cookies["Register"]["UserName"] == txtUserLogin.Text && Request.Cookies["Register"]["Password"] == txtPassLogin.Text)
            {
                Session["UserName"] = Request.Cookies["Register"]["Fullname"];
                Response.Redirect("~/Default.aspx");
            }
            else
            {
                lbStatusLogin2.Text = "Login Failed. Invalid user name and password. Do you want to register?";               
                munviLogin.ActiveViewIndex = 2;
            }
        }
        else
        {
            lbStatusLogin2.Text = "Login Failed. Invalid user name and password. Do you want to register?";            
            munviLogin.ActiveViewIndex = 2;
        }
    }
    protected void btCancel_Click(object sender, EventArgs e)
    {
        munviLogin.ActiveViewIndex = 0;
        txtUserLogin.Focus();
    }
    protected void btOkRegister_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/Register.aspx");
    }
}